using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.Multimedia.Library;
using NCS.Module.Multimedia.Library.Gallery;
using NCS.Library.Utilities;
using NCS.Library;

namespace NCS.Module.Multimedia.Web.Gallery
{
    public partial class GalleryGetTop : GalleryWebControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int catid = ConvertUtility.ToInt32(Request.QueryString["catid"]);
            if (catid != 0)
            {
                Advertisement1.Param = "catid";
            }
            
            rptGallery.DataSource = Gallery_AlbumController.GetAlbumByNum(3);
            rptGallery.ItemDataBound += new RepeaterItemEventHandler(rptGallery_ItemDataBound);
            rptGallery.DataBind();
           
        }

        void rptGallery_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemIndex < 0) return;
            DataRowView currow = (DataRowView)e.Item.DataItem;
            Image imgPic = (Image)e.Item.FindControl("imgPic");
            HyperLink hplTitle = (HyperLink)e.Item.FindControl("hplTitle");
            Literal litSummary = (Literal)e.Item.FindControl("litSummary");
            
            if (Gallery_AlbumController.GetAllAlbumByParentID(ConvertUtility.ToInt32(currow["AlbumID"])).Rows.Count > 0)
            {
                hplTitle.NavigateUrl = BuildUrlByAlbum(ConvertUtility.ToInt32(currow["AlbumID"]));
                if (ConvertUtility.ToString(currow["AlbumAvatar"]) != string.Empty)
                {
                    imgPic.ImageUrl = MultimediaUtility.GetGalleryAvatar(currow["AlbumAvatar"].ToString());
                    imgPic.Attributes.Add("onclick", "window.location='" + BuildUrlByAlbum(albumid) + "'");
                    imgPic.Attributes.Add("style", "cursor:hand");
                }
                else
                {
                    imgPic.Visible = false;
                }
                hplTitle.Text = ConvertUtility.ToString(currow["AlbumName"]);
                litSummary.Text = ConvertUtility.ToStringWithoutFontBoldLength(currow["AlbumDetail"], ConvertUtility.ToString(currow["AlbumName"]).Length);
            }
            else
            {
                hplTitle.NavigateUrl = BuildUrlByPicInAlbum(ConvertUtility.ToInt32(currow["AlbumID"]));
                if (ConvertUtility.ToString(currow["AlbumAvatar"]) != string.Empty)
                {
                    imgPic.ImageUrl = MultimediaUtility.GetGalleryAvatar(currow["AlbumAvatar"].ToString());
                    imgPic.Attributes.Add("onclick", "window.location='" + BuildUrlByPicInAlbum(albumid) + "'");
                    imgPic.Attributes.Add("style", "cursor:hand");
                }
                else
                {
                    imgPic.Visible = false;
                }
                hplTitle.Text = ConvertUtility.ToString(currow["AlbumName"]);
                litSummary.Text = ConvertUtility.ToStringWithoutFontBoldLength(currow["AlbumDetail"], ConvertUtility.ToString(currow["AlbumName"]).Length);
            }
        }
    }
}